package com.tbsoft.ehr.login;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.tbsoft.ehr.model.BaseEntity;
/**
 * @desc 角色
 * @author vastdream
 *
 */
@Entity
@Table(name="EHR_ROLE")
public class RoleInfo  extends BaseEntity{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 角色ID
	 */
	private String roleId;
	/**
	 * 角色名称
	 */
	private String roleName;
	/**
	 * 用户列表
	 */
	private Set<UserInfo> userInfoSet= new HashSet<UserInfo>();
	private Set<MenuInfo> menuSet = new HashSet<MenuInfo>();
	@Id
	@Column(name="ROLE_ID" ,length=10)
	public String getRoleId() {
		return roleId;
	}
	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}
	@Column(name="ROLE_NAME",length=15)
	public String getRoleName() {
		return roleName;
	}
	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}
	@ManyToMany(mappedBy="roleSet",fetch=FetchType.EAGER,cascade={CascadeType.MERGE})
	public Set<UserInfo> getUserInfoSet() {
		return userInfoSet;
	}
	public void setUserInfoSet(Set<UserInfo> userInfoSet) {
		this.userInfoSet = userInfoSet;
	}
	@ManyToMany(targetEntity=MenuInfo.class,fetch=FetchType.EAGER,cascade={CascadeType.MERGE})
	@JoinTable(name="EHR_ROLE_MENU",
		joinColumns={@JoinColumn(referencedColumnName="ROLE_ID")},
		inverseJoinColumns={@JoinColumn(referencedColumnName="MENU_ID")}
	)
	public Set<MenuInfo> getMenuSet() {
		return menuSet;
	}
	public void setMenuSet(Set<MenuInfo> menuSet) {
		this.menuSet = menuSet;
	}
	@Override
	public int hashCode() {
		return (""+roleId).hashCode();
	}
	@Override
	public boolean equals(Object obj) {
		if(obj instanceof RoleInfo)
			return (""+roleId).equals(((RoleInfo)obj).getRoleId());
		else
			return false;
			
	}
	@Override
	public String toString() {
		return roleId+":"+roleName;
	}
	
	private boolean select=false;
	@Transient
	public boolean isSelect() {
		return select;
	}
	public void setSelect(boolean select) {
		this.select = select;
	}
	
}
